package com.cloud.force.api.service.impl;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cloud.force.api.command.transit.TransitRequest;
import com.cloud.force.api.command.transit.TransitResponse;
import com.cloud.force.api.handler.HandlerChain;
import com.cloud.force.api.handler.Request;
import com.cloud.force.api.handler.Response;
import com.cloud.force.api.handler.common.OverTimeLogHandler;
import com.cloud.force.api.handler.common.TestJdbcTemplate2Handler;
import com.cloud.force.api.handler.common.TestJdbcTemplateHandler;
import com.cloud.force.api.handler.common.TestMyBatisMapperHandler;
import com.cloud.force.api.service.TaskListExecuteService;

@Service
@Transactional
public class TaskListExecuteServiceImpl implements TaskListExecuteService, ApplicationContextAware{
	private ApplicationContext applicationContext;
	
	@Override
	public void execute(Request request, Response response) {
		//从流程上获取流向事件，加入固定类型事件：计时、指令执行时长日志
		HandlerChain chain = new HandlerChain();
		chain.setApplicationContext(applicationContext);
		Request req = new TransitRequest();
		Response resp = new TransitResponse();
		chain.addHandler(new OverTimeLogHandler())
			.addHandler(new TestJdbcTemplate2Handler())
			.addHandler(new TestJdbcTemplateHandler())
			.addHandler(new TestMyBatisMapperHandler());
		chain.doHandler(req, resp);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

}
